from logicaltool.BaseTools.file_tools import FileTools
from xjlibrary.our_file_dir import BaseDir


class DataBaseTools(FileTools):

    def __init__(self):
        super().__init__()

    def sql_go_hadoop(self):
        """
        该函数的使用场景为去除hadoop上已经解析了的数据目的是为了
        防止本地与Hadoop不同步问题 已本地去除hadoop的剩余的就是我们需要的
        数据
        :return:
        """
        thisdir = BaseDir.get_file_dir_absolute(__file__)
        self.config_file = BaseDir.get_new_path(thisdir, "db.ini")
        # 连接db3文件
        self.conn_sqlite3("./cnkicstad.db3")
        # 连接mysql
        self.conn_mysql("sql_go_hadoop")
        self.sql = "select filename from article"
        rows = self.mysql_select()
        for row in rows:
            self.inputobj1.add(row[0])

        self.sql = "select rawid from modify_title_info_zt"
        rows = self.sqlite_select()
        for row in rows:
            self.inputobj2.add(row[0])
        self.inputobj3 = self.inputobj1 - self.inputobj2
        updatesql = "update article set stat=0 where filename in {}".format(tuple(self.inputobj3))
        print(updatesql)


if __name__ == "__main__":
    databasetools = DataBaseTools()
    databasetools.sql_go_hadoop()
